<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | Delete Account</title>
<?php include_once("common_script_inclusions.php"); ?>
</head>

<body>
<?php


require_once("includes/pagetop.php");
if(isset($_SESSION['Allyfolio_User_ID']))
{   
    if($_SESSION['Allyfolio_User_ID']<0){
        redirect("accountblocked.php");    
    }
}
else{
    redirect("index.php");
}
?>
	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<div class="wrapper row1">
	<div class="header">
    	<div class="log_button">
		<table width="744" border="0" style="margin-top:5px;">
			<tr>
				<td width="24">
					<a href="#"><img src="images/navico_1.png" /></a>				</td>
				<td width="36">
					<a href="#"><img src="images/navico_2.png" /></a>				</td>
				<td width="26">
					<a href="#"><img src="images/navico_3.png" /></a>				</td>
				<td width="30">
					<a href="#"><img src="images/navico_4.png" /></a>				</td>
					<td width="594">
					<!--<ul class="dn_txt3">
						<li><img src="images/dna_txt_right.png" /></li>
						<li><input type="text" class="dna_txt2" /></li>
						<li><img src="images/dna_txt_left.png" /></li>
					</ul>-->
					
					</td>
			</tr>
		  </table>
		</div>
		
       
    	
        <a href="index.html" class="logo"></a>
    </div>
    <div class="clearfix"></div>  
    
    
    </div>
    <div class="clearfix"></div>
    <!--=================Header end=======================-->
    
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
      <div class="header acSetting">
          <h1>Settings</h1>
     <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td style="vertical-align: top;">
                          <div >
                          <?php  
                          include_once("settings_menu.php");
                          ?>
                          </div>
                    </td>
                    <td style="vertical-align: top;">
                        <?php
                        $isAccountRemoved=false;
                        if(isset($_REQUEST["acrmv"]) && trim($_REQUEST["acrmv"])=="true"){
                            $isAccountRemoved=true;
                        }
                        if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']==-1){
                            $isAccountRemoved=true;
                        }
                        if(!$isAccountRemoved){
                        ?>
                        <form name="frmaccountdelsettings" id="frmaccountdelsettings" action="ajax/generic_crudoperations.php">
                            <div class="acSettingSecR" style="width:743px;">
                                <div class="fieldSec">
                                <label style="color:#f00;">Delete Account</label> 
                                <input type="button" value="Delete" onclick="confirmAction(this, 'Are you sure you wish to remove this?', performDelete); return false;"/>
                            </div>
                            
                            <br />
                            <div id="light_delfeedback" style="display: none;">
                                <table>
                                    <tr>
                                        <td>
                                            <br />
                                            <strong>Please give us your precious Feedback.</strong>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <br />
                                            <textarea rows="9" style="width:90%;" id="txtfeedbackdel" name="txtfeedbackdel" placeholder="Write here...." ></textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <br />
                                            <input type="button" name="cmdSendFeedBack" id="cmdSendFeedBack" value="Send" style="margin-left:294px;" onclick="return sendFeedBack();"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <br /><br /><br />
                            
                            </div>
                         </form>
                         <?php
                         }else{
                           unset($_SESSION['Allyfolio_User_ID']);
                           session_destroy();
                           /*
                           if(isset($_COOKIE['key'])) {
                              unset($_COOKIE['key']);
                              setcookie('key', '', time() - 3600); // empty value and old timestamp
                            }
                            */
                         ?>  
                         <div style="float: left;">
                            <div style="margin-top: 30px;">
                                <strong>Your account is no more available now..</strong>
                            </div>
                         </div>   
                         <?php
                         }
                         ?>
                    </td>
     </tr>
     </table>
     </div>
     </div>
     
    
 	
	
	 
    </div>
    
    
    <div class="clearfix"></div>
    <script type="text/javascript">
        function performDelete ( a_element ) {
            // perform your delete here
            // a_element is the <a> tag that was clicked
            var urlstr = $("#frmaccountdelsettings").attr( "action" );
            $.ajax({
        	  	type: "POST",
        	  	url: urlstr,
        	  	cache: false,
        	  	data: { 
        	  	         "actiontype":"remove_my_account"
                      } 
            })
        	.done(function( data ) {	
        	   var jsonParsed=$.parseJSON(data);
                if(!isNaN(jsonParsed.err)){ //means have some code
                    switch(parseInt(jsonParsed.err)){
                        case 200:
                                //light_delfeedback
                                if($("#light_delfeedback").css("display")!="none"){
                                    isStatusOpenedAsPopup=true;
                                    $("#light_delfeedback").addClass("statuspopupdiv"); 
                                    lightbox_open("light","fade","delfeedback");
                                }
                                else{
                                    isStatusOpenedAsPopup=false;
                                    lightbox_closeCurrent();
                                } 
                                $("#light_delfeedback").css("display","");
                                break;
                        default:
                                alert(jsonParsed.msg);
                                break;
                    }
                }
        	})
        	.fail(function(msg) { 
        		console.log(msg);
        //		alert("error"); 
        	})
            .always(function() { 
        		//alert("complete"); 
        	});
        }
        
        function confirmAction ( a_element, message, action ) {
            alertify.confirm(message, function(e) {
                if (e) {
                    // a_element is the <a> tag that was clicked
                    if (action) {
                        action(a_element);
                    }
                }
            });
        }
        
        
function sendFeedBack(){
        
    var formS = document.getElementById("frmaccountdelsettings");
    var urlstr = $("#frmaccountdelsettings").attr( "action" );
    // Send the data using post
    $.ajax({
	  	type: "POST",
	  	url: urlstr,
	  	cache: false,
	  	data: { 
	  	         "actiontype":"account_removed_feedback",   
	  	         "feedback_message": document.getElementById('txtfeedbackdel').value
              } 
    })
	.done(function( data ) {	
	   //alert(data);
	   var jsonParsed=$.parseJSON(data);
        console.log(jsonParsed);
        /*if(document.getElementById("errconsole")){
            document.getElementById("errconsole").innerHTML=data;
        }*/
        if(!isNaN(jsonParsed.err)){ //means have some code
            switch(parseInt(jsonParsed.err)){
                case 200:
                        window.location.href=window.location.href+"?acrmv=true";
                        break;
                default:
                        alert(jsonParsed.msg);
                        break;
            }
        }
	})
	.fail(function(msg) { 
		console.log(msg);
//		alert("error"); 
	})
    .always(function() { 
		//alert("complete"); 
	});
    return false;  
}

    </script>
    <div id="fade" onclick="lightbox_closeCurrent();">

 </body>
</html>
